package com.tlvip.redis;

import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;
import redis.clients.jedis.JedisPoolConfig;

/**
 * <p>description：</p>
 * <p>copyright： copyright(C)2016-2099</p>
 * <p>Life is short,we need passion</p>
 * <p>Summary： </p>
 * <p>instructions： </p>
 * Date 2/2/21</p>
 * Author mac
 *
 * @version 1.0
 */
public class RedisTest {
    private static Jedis jedis;

    public static Jedis init(String host, int port) {
        jedis = new Jedis(host, port);
        return jedis;
    }

    public static Jedis init(String host, int port, String password) {
        jedis = init(host, port);
        jedis.auth(password);
        return jedis;
    }

    public static String set(String key, String value) {
        String result = jedis.set(key, value);
        return result;
    }


    public static String get(String key) {
        return jedis.get(key);
    }

    public static boolean del(String key) {
        long result = jedis.del(key);
        return result == 1;
    }

    public static void main(String[] args) {
//        init("127.0.0.1", 6379, "123456");
        init("127.0.0.1", 6379);

        String key = "com:mac";
        String value = "apple";

        System.out.println(set(key, value));
        System.out.println(get(key));
        System.out.println(del(key));
        System.out.println(get(key));
    }


}
